<!DOCTYPE html>
<html>

<head lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0" />
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">
    <title>登录</title>
    <link type="image/x-icon" rel="shortcut icon" href="../images/favicon.ico">
    <link rel="stylesheet" href="../res/mui/css/mui.min.css" />
    <link rel="stylesheet" href="../res/fontAwesome/css/font-awesome.min.css" />
    <link rel="stylesheet" href="../css/common.css" />
    <link rel="stylesheet" href="../css/user.css" />
</head>

<body>
    <div class="cz_layout">
        <header class="cz_topBar">
            <a href="javascript:history.back();" class="icon_back fa fa-arrow-left"></a>
            <span class="title">登录</span>
        </header>
        <div class="cz_container">
            <form action="">
                <div class="form_box">
                    <div class="mui-input-row">
                        <input name="username" type="text" placeholder="用户名/手机号">
                    </div>
                    <div class="mui-input-row">
                        <input name="password" type="password" placeholder="密码" class="mui-input-password">
                        <span class="mui-icon mui-icon-eye"></span>
                    </div>
                    <a href="javascript:;" class="mui-btn mui-btn-primary btn_login">登录</a>
                    <div class="mui-input-row cz_text">
                        <a href="register.html">免费注册</a>
                    </div>
                </div>
            </form>
        </div>
        <footer class="cz_tabs">
            <a class="tab_home fa fa-home" href="../index.html"><span>首页</span></a>
            <a class="tab_cate fa fa-bars" href="../cate.html"><span>分类</span></a>
            <a class="tab_cart fa fa-shopping-cart" href="../cart.html"><span>购物车</span></a>
            <a class="tab_user fa fa-user" href="/user/index.html"><span>会员中心</span></a>
        </footer>
    </div>
    <script src="../res/mui/js/mui.min.js"></script>
    <script src="../assets/vendors/jquery/jquery.min.js"></script>
    <script src="../assets/vendors/layer/layer.js"></script>
    <script>
        // console.log(location.search);
        var newUrl = location.search;
        // newUrl=newUrl.slice(500);
        // console.log(newUrl);

        if (newUrl == '') {
            newUrl = '/index.html'
        } else {
            newUrl = newUrl.slice(5);
            console.log(newUrl);
        }

        $('.btn_login').click(function () {
            var data = $('form').serialize();
            console.log(data);
            $.ajax({
                url: '/api/user/login',
                type: 'post',
                data: data,
                success: function (msg) {
                    if (msg.success) {
                        layer.ready(function () {
                            layer.msg('登录成功', {
                                    shift: 5,
                                    time: 1000
                                },
                                function () {
                                    location.href = newUrl;
                                });
                        });

                    }
                }
            });

        });
    </script>
</body>

</html>